package com.example.shop_2210.adapter

import android.annotation.SuppressLint
import android.graphics.drawable.ColorDrawable
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CategoryEntityResult
import com.example.base.mvvm.BaseViewModel
import com.example.shop_2210.R

class OneAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_one) {
    var selectedId = 515
    @SuppressLint("ResourceAsColor")
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.name,item.name)
        holder.getView<TextView>(R.id.name).background = if(item.id==selectedId)
            ColorDrawable(R.color.red) else null
    }
    fun setId(id:Int){
        selectedId = id
        notifyDataSetChanged()//刷新适配器，不然不起作用
    }
}